package com.example.demo.controller;

import lombok.Data;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.PostConstruct;

/**
 * Created with Intellij IDEA.
 * Description:
 * User: 33013
 * Date: 2024-02-05
 * Time: 14:07
 */
//@Component引入依赖
//@Autowride注入依赖
//@Value($"{配置项}")读取配置项,去掉$就会吧“”里的数据当成字符串赋值给变量
@RequestMapping("/response")//
@Controller//返回视图
public class Response {
    @RequestMapping("/Html")
    public String returnHtml(){
        return "/Index.html";
    }

    @ResponseBody//可以修饰类，特可以修饰方法，表示返回数据。
    @RequestMapping("/Index")
    public String returnHtml2(){
        return "dasdhaiu";
    }

    @ResponseBody//可以修饰类，特可以修饰方法，表示返回数据。
    @RequestMapping("/json")//
    public Person returnjson(){
        Person person = new Person();
        return person;
    }//当返回的是String类型的话，content-type是text/html
    //当返回的是对象或map时，content-type是json"

    @ResponseBody
    //@PostConstruct初始化方法//
    @RequestMapping(value = "/m15", produces = "application/json; charset=utf-8")
    public String m15(){
        return "json";
    }//指定返回类型json

    @ResponseBody
    @RequestMapping(value = "/m16", consumes = "application/json; charset=utf-8")
    public String m16(){
        return "json";
    }//指定接收类型json
}
